<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #myProgress {
            width: 70%;
            height: 30px;
            /* position: relative; */
            background-color: #ddd;
        }

        #myBar {
            background-color: #4CAF50;
            width: 10px;
            height: 30px;
            /* position: absolute; */
        }
    </style>
</head>

<body>
    <!-- <h1>JavaScript 进度条</h1>

    <div id="myProgress">
        <div id="myBar"></div>
    </div>
    <br>
    <button>点我</button> -->
    <script>
        let myProgress = document.getElementById('myProgress')
        let myBar = document.getElementById('myBar')
        let btn = document.getElementsByTagName('button')[0]
        // btn.onclick = function () {
        //     let t = setInterval(() => {
        //         // clientWidth content+padding 
        //         myBar.style.width = myBar.clientWidth + 2 + 'px'
        //         myBar.clientWidth > myProgress.clientWidth ? clearInterval(t) : null
        //     }, 10)

        // }

        // document.body.style.background = 'green'
        // [min ,max)
        let rand = function (min, max) {
            return Math.floor(Math.random() * (max - min) + min)
        }
        let colorArr = ['red', 'blue', 'green', 'pink', 'gray', 'yellow', 'white', 'black']
        let len = colorArr.length
        let t = setInterval(() => {
            document.body.style.background = colorArr[rand(0, len)]
        }, 2000)

    </script>
</body>

</html>